package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Topic;
import com.woniuxy.entity.dto.TopicUserDto;
import com.woniuxy.service.TopicService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 杜昊男  <br/>
 * Date: 2022/3/15:11:24  <br/>
 * Description:
 */
@RestController
@RequestMapping("/topic")
public class TopicController {
    @Autowired
    TopicService topicService;

    @ApiOperation(value = "创建试卷")
    @PostMapping("/createTopic")
    public ResponseEntity createTopic(@RequestBody Topic topic) {
        return topicService.createTopic(topic);
    }

    @ApiOperation(value = "删除试卷")
    @DeleteMapping("/deleteTopic/{id}")
    public ResponseEntity deleteTopic(@PathVariable("id") int topicid) {
            Topic topic = new Topic();
            topic.setId(topicid);
        return topicService.deleteTopic(topic);
    }
    @ApiOperation(value = "更新试卷信息")
    @PutMapping("/updateTopic")
    public ResponseEntity updateTopic(@RequestBody Topic topic) {
        return topicService.updateTopic(topic);
    }

    @ApiOperation(value = "查找试卷")
    @PostMapping("/findTopic/{pageNum}/{pageSize}")
    public ResponseEntity findTopic(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize, @RequestBody Topic topic) {
        return topicService.findTopic(pageNum, pageSize, topic);
    }
    @ApiOperation(value = "查询用户对应的所有试卷")
    @GetMapping("/findTopicByUserId/{userid}")
    public ResponseEntity findTopicByUserId(@PathVariable("userid") int userid) {
        return topicService.findTopicByUserId(userid);
    }
    @ApiOperation(value = "查询培训下对应的试卷")
    @GetMapping("/findTopicByTrainindId/{trainingid}")
    public ResponseEntity findTopicByTrainingId(@PathVariable("trainingid") int trainingid) {
        return topicService.findTopicByTrainingId(trainingid);
    }
    @ApiOperation(value = "查询用户对应培训的考试")
    @GetMapping("/findTopicByUserIdAndTopicId/{userid}/{topicid}")
    public ResponseEntity findTopicByUserIdAndTopicId(@PathVariable("userid") int userid, @PathVariable("topicid") int topicid) {
        return topicService.findTopicByUserIdAndTopicId(userid, topicid);
    }

    @ApiOperation(value = "提交试卷成绩")
    @PostMapping("/submitTopic")
    public ResponseEntity submitTopic(@RequestBody TopicUserDto topicUserDto) {
        return topicService.submitTopic(topicUserDto);
    }
}
